using System;
using System.Text.RegularExpressions;

namespace DNT.RavenQA.Core.KeyResolving
{
    internal class Int32Resolver : IKeyResolver
    {
        public Object Resolve(String source)
        {
            var match = Regex.Match(source, @"\d+").Value;
            Int32 id;

            if (!Int32.TryParse(match, out id))
                throw new FormatException("Invalid id format.");

            if (id == 0)
                throw new FormatException("Id cannot be zero.");

            return id;
        }
    }
}